<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2020/7/30
 * Time: 10:47
 */

namespace app\alliance\controller;


use think\Controller;
use think\Db;

class Api extends Controller
{
    /**
     * @return array
     * @throws \think\Exception
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @cpntent 玩家消费之后 添加积分
     */
    function addIntegral()
    {
        # 手机号
        $phone = input('post.phone');
        # 消费记录
        $logConsumption = input('post.logConsumption');
        if (!empty($phone) and !empty($logConsumption)) {
            # 手机号验证
            $isPhone = checkMobile($phone);
            if ($isPhone) {
                # 查询玩家是否存在
                $memberCode = Db::table('member')->field('code')->where(array('phone' => $phone))->find()['code'];
                if (!empty($memberCode)) {
                    # 加积分
                    $res = addIntegral_branch($logConsumption, $memberCode);
                    return $res;
                } else {
                    # 未注册
                    return array('status' => false, 'msg' => '未注册');
                }
            } else {
                # 手机号不正确
                return array('status' => false, 'msg' => '手机号不正确');
            }
        } else {
            # 参数存在空值
            return array('status' => false, 'msg' => '参数存在空值');
        }
    }

    /**
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @conten 通过code查询code
     */
    function getMemberCode()
    {
        # 手机号
//        $code = strtoupper(input('post.member_code'));
        $phone = strtoupper(input('post.phone'));
        if (!empty($phone)) {
//            # 手机号验证
//            $isPhone = checkMobile($phone);
//            if ($isPhone) {
            # 查询玩家是否存在
            $memberCode = Db::table('member')->field('code,status,type')->where(array('phone'=>$phone))->find();
            if (!empty($memberCode)) {
                # 查询成功
                return array('status' => true, 'msg' => '查询成功', 'memberInfo' => $memberCode);
            } else {
                # 不存在
                return array('status' => false, 'msg' => '信息不存在');
            }
//            } else {
//                # 手机号不正确
//                return array('status' => false, 'msg' => '手机号不正确');
//            }
        } else {
            return array('status' => false, 'msg' => '玩家ID为空');
        }
    }
}